package vn.cent.game.cardtype.bc;

import vn.cent.game.cardtype.beans.IUser;
import vn.cent.game.cardtype.utils.FaceType;
import vn.cent.game.cardtype.utils.GameKind;

public class BCPlayer extends IUser {

	public BCFace[] betList;
	
	
	
	public BCPlayer(int ID, int roomID, boolean isReady, GameKind game) {
		super(ID, roomID, isReady, game);
		Setup();
	}
	
	public BCPlayer()
	{
		super();
		Setup();
	}
	
	private void Setup()
	{
		trace("Setup bet list");
		betList = new BCFace[6];
		int i = 0;
		for (i = 0; i < betList.length; i++)
		{
			betList[i] = new BCFace();
		}
		
		betList[0].setFaceValue(FaceType.Gourd);
		betList[1].setFaceValue(FaceType.Crab);
		betList[2].setFaceValue(FaceType.Shrimp);
		betList[3].setFaceValue(FaceType.Fish);
		betList[4].setFaceValue(FaceType.Chicken);
		betList[5].setFaceValue(FaceType.Deer);
		
		CleanBetList();
	}
	
	
	private void CleanBetList()
	{
		int i = 0;
		for (i = 0; i < betList.length; i++)
		{
			betList[i].isBetted = false;
			betList[i].betAmount = 0;
		}
	}
	
	public void UpdateBetList(String name, int betAmount)
	{
		trace("[BCPlayer] Update bet list with face type = " + name + " and bet amount = " + betAmount);
		FaceType value = SwichToMakeIndex(name);
		
		int i = 0;
		
		trace("[BCPlayer] Check with bet list length = " + betList.length);
		
		for (i = 0; i < betList.length; i++)
		{
			if (betList[i].getFaceValue() == value)
			{
				trace("[BCPlayer] Set face = " + betList[i].getFaceValue() + " and amount =   " + betAmount);
				betList[i].isBetted = true;
				betList[i].betAmount = betAmount;
			}
		}
	}
	
	private FaceType SwichToMakeIndex(String name)
	{
		FaceType value = FaceType.None;
		switch (name)
		{
			case "Gourd":
				{
					value = FaceType.Gourd;
					break;
				}
			case "Crab":
				{
					value = FaceType.Crab;
					break;
				}
			case "Shrimp":
				{
					value = FaceType.Shrimp;
					break;
				}
			case "Fish":
				{
					value = FaceType.Fish;
					break;
				}
			case "Chicken":
				{
					value = FaceType.Chicken;
					break;
				}
			case "Deer":
				{
					value = FaceType.Deer;
					break;
				}
		}
		return value;
	}

	
	public void UpdateAccountBalance(int updateAmount, boolean isAdd)
	{
		if (isAdd)
		{
			accountBalance += updateAmount;
		}
		else
		{
			accountBalance -= updateAmount;
		}
	}
	
	
	
}
